package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.system.mapper.Test1Mapper;
import org.jeecg.modules.system.service.Test1Service;
import org.jeecg.modules.system.vo.DataItem;
import org.jeecg.modules.system.vo.QueryParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Test1ServiceImpl implements Test1Service {

    @Autowired
    private Test1Mapper test1Mapper;

    @Override
    public Page<DataItem> queryPage(QueryParams queryParams) {
        Page<DataItem> page = new Page<>(queryParams.getPage(), queryParams.getPageSize());
        QueryWrapper<DataItem> wrapper = new QueryWrapper<>();
        wrapper.lambda().like(StringUtils.isNotBlank(queryParams.getName()), DataItem::getName, queryParams.getName())
                .eq(null != queryParams.getSex(), DataItem::getSex, queryParams.getSex());
        Page<DataItem> dataItemPage = test1Mapper.selectPage(page, wrapper);
        return dataItemPage;
    }

    @Override
    public int saveOrUpdate(DataItem param) {
        int num;
        if (null == param.getId()) {
            num = test1Mapper.insert(param);
        } else {
            num = test1Mapper.updateById(param);
        }
        return num;
    }

    @Override
    public int deleteById(int id) {
        return test1Mapper.deleteById(id);
    }

    @Override
    public DataItem details(Integer id) {
        return test1Mapper.selectById(id);
    }
}
